
var menuDom={};
setTimeout(function () {
	menuDom = {
		personalInfo:$("li[route='personalInfo'] a cite"),
		// domain:$("li[route='myDomain'] a cite"),
		educationExperience:$("li[route='educationExperience'] a cite"),
		workExperience:$("li[route='workExperience'] a cite"),
		awardCertificate:$("li[route='awardCertificate'] a cite"),
		scientificResearch:$("li[route='scientificResearch'] a cite"),
		patent:$("li[route='patent'] a cite"),
		// onceProject:$("li[route='onceProject'] a cite"),
		baseInfo:$("li[name='基本信息'] > a  > cite"),
		speciltyInfo:$("li[name='学术及专业能力信息'] > a > cite")
	}
},500);

var menus = [{
	"name": "基本信息",
	"icon": "&#xe749;",
	"route": "",
	"children": [{
		"name": "认证信息",
		"route": "certification",
		"children": false
	},{
		"name": "个人情况",
		"route": "personalInfo",
		"children": false
	},{
		"name": "教育经历",
		"route": "educationExperience",
		"children": false
	}, {
		"name": "工作经历",
		"route": "workExperience",
		"children": false
	}]
},{
	"name": "学术及专业能力信息",
	"icon": "&#xe749;",
	"route": "",
	"children": [{
		"name": "奖励情况",
		"route": "awardCertificate",
		"children": false
	}, {
		"name": "科研组织任职",
		"route": "scientificResearch",
		"children": false
	}, {
		"name": "专利及著作权",
		"route": "patent",
		"children": false
	}//, {
	//	"name": "曾参选的项目",
	//	"route": "onceProject",
	//	"children": false
//	}
	]
}, {
	"name": "我的研究内容",
	"icon": "&#xe749;",
	"route": "myTopic",
	"children": false
}, {
	"name": "我的推优项目",
	"icon": "&#xe749;",
	"route": "declaredProject",
	"children": false
}, {
	"name": "院士专家信息",
	"icon": "&#xe6b8;",
	"route": "academicianInfo",
	"children": false
},  {
	"name": "组织机构信息",
	"icon": "&#xe6b8;",
	"route": "organInfo",
	"children": false
},{
	"name": "研究内容（三级目录）",
	"icon": "&#xe6b4;",
	"route": "topicInfo",
	"children": false
},{
	"name": "dashboard",
	"icon": "&#xe749;",
	"route": "dashboard",
	"children": false
}];

// 构建左侧菜单栏
layui.use(['jquery'], function() {
	var $ = jQuery = layui.$;

	var menuHtml = "";
	menus.forEach(function(data) {
		menuHtml += isHaveChildren(data);
	});
	$("#nav").html(menuHtml);

	// 副标题
	$("#nav>li").eq(0).before('<div class="sml_title sml_title_top applicant_info"><span>院士专家信息</span><hr class="layui-bg-cyan"></div>');
	$("#nav>li").eq(2).before('<div class="sml_title sml_title_top workbench"><span>项目信息</span><hr class="layui-bg-cyan"></div>');
	$("#nav>li").eq(4).before('<div class="sml_title sml_title_top discover"><span>查询信息</span><hr class="layui-bg-cyan"></div>');


	$("li[name='dashboard']").hide();
	// 获取后台数据
	// 	AJAX.query("http://testdpmpapi.dmall.com/project/overviewCount", "", function(res) {
	// 		console.log(res)
	// 	});
});

// 判断是否存在子集
function isHaveChildren(data) {
	var html = '';
	var icon = isHaveIcon(data);
	if (data.children && data.children.length) { // 存在子集
		var childrenHtml = getChildrenHtml(data.children);
		html += '<li name="' + data.name + '" route="' + data.route + '">';
		html += '<a href="javascript:;">';
		html += '<i class="iconfont" lay-tips="' + data.name + '">' + icon + '</i>';
		html += '<cite>' + data.name + '</cite>';
		html += '<i class="iconfont nav_right">&#xe697;</i>';
		html += '</a>';
		html += childrenHtml;
		html += '</li>';
	} else { // 不存在子集
		html += '<li name="' + data.name + '" route="' + data.route + '">';
		html += '<a>';
		html += '<i class="iconfont" lay-tips="' + data.name + '">' + icon + '</i>';
		html += '<cite>' + data.name + '</cite>';
		html += '</a>';
		html += '</li>';
	}

	return html;
}

// 获取子集内容
function getChildrenHtml(data) {
	var html = '<ul class="sub-menu">';
	data.forEach(function(info) {
		html += isHaveChildren(info); // 判断是否存在子集
	});
	html += '</ul>';

	return html;
}

// 判断是否有Icon
function isHaveIcon(data) {
	var icon = "";
	if (data.icon) {
		icon = data.icon;
	} else {
		icon = "&#xe6a7;";
	}
	return icon;
}


function setMenuNotCompleteColor(infos) {
	console.log(infos);
	var baseInfoParent = 0;
	var specialtyParent = 0;

	if(!infos.personalInfo){
		menuDom.personalInfo.addClass('wait_complete');
		baseInfoParent +=1;
	}else{
		menuDom.personalInfo.removeClass('wait_complete');
	}

	// if(!infos.domain){
	// 	menuDom.domain.addClass("wait_complete");
	// 	baseInfoParent +=1;
	// }else{
	// 	menuDom.domain.removeClass("wait_complete");
	// }

	if(!infos.educationExperience){
		menuDom.educationExperience.addClass('wait_complete');
		baseInfoParent += 1;
	}else{
		menuDom.educationExperience.removeClass('wait_complete');
	}
	if(!infos.workExperience){
		menuDom.workExperience.addClass('wait_complete');
		baseInfoParent += 1;
	}else{
		menuDom.workExperience.removeClass('wait_complete');
	}


	if(!infos.scientificResearch){
		menuDom.scientificResearch.addClass('wait_complete');
		specialtyParent += 1;
	}else{
		menuDom.scientificResearch.removeClass('wait_complete');
	}
	if(!infos.awardCertificate){
		menuDom.awardCertificate.addClass('wait_complete');
		specialtyParent += 1;
	}else{
		menuDom.awardCertificate.removeClass('wait_complete');
	}

	if(!infos.patent){
		menuDom.patent.addClass('wait_complete');
		specialtyParent += 1;
	}else{
		menuDom.patent.removeClass('wait_complete');
	}

	// if(!infos.onceProject){
	// 	menuDom.onceProject.addClass('wait_complete');
	// 	specialtyParent += 1;
	// }else{
	// 	menuDom.onceProject.removeClass('wait_complete');
	// }



	if(baseInfoParent > 0){
		menuDom.baseInfo.addClass('wait_complete');
	}else{
		menuDom.baseInfo.removeClass('wait_complete');
	}

	if(specialtyParent > 0){
		menuDom.speciltyInfo.addClass('wait_complete');
	}else{
		menuDom.speciltyInfo.removeClass('wait_complete');
	}




}

function  checkInfoComplete() {
	AJAX.query(cgiMain.academistInfoItemCompletion,
		{},
		function (res) {
			if(res.code=="0000"){
				setMenuNotCompleteColor(res.result);
			}else{
				setMenuNotCompleteColor({});
			}
		});
	//设置我的研究内容
	AJAX.post(cgiMain.academistSubjectList,
		{pageNum:1,pageSize:10},
		function (res) {

			if(res.code == '0000') {
				$("li[name='我的研究内容'] > a > cite").removeClass('wait_complete');
			}else{
				$("li[name='我的研究内容'] > a > cite").addClass('wait_complete');
			}
		});
	//设置我的推优项目
	AJAX.post(cgiMain.academistApplyMe,
		{pageNum:1,pageSize:10},
		function (res) {

			if(res.code == '0000') {
				$("li[name='我的推优项目'] > a > cite").removeClass('wait_complete');
			}else{
				$("li[name='我的推优项目'] > a > cite").addClass('wait_complete');
			}
		});
}
